package com.chicken.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chicken.pojo.Member;
import com.chicken.service.MemberService;
import com.chicken.service.MemberUpdateService;
import com.google.gson.Gson;

@Controller
@RequestMapping(value="/list")
public class MemberController {
	@Resource
	private MemberService memberService;
	
	@Resource
	private MemberUpdateService memberUpdateService;
	
	@RequestMapping(value="/loginAll",method=RequestMethod.GET)
	@ResponseBody
	public String loginAll(HttpServletRequest req){
		String username=req.getParameter("username");
		String password=req.getParameter("password");
	 int loginAll = memberService.loginAll(username, password);
	 //System.out.println("======================"+loginAll);
		Gson g=new Gson();
		String json = g.toJson(loginAll);
		return json;
	}
	
	
	@RequestMapping(value="/selectbyname",method=RequestMethod.GET)
	@ResponseBody
	public String selectbyname(HttpServletRequest req){
      String username=req.getParameter("username");
	    Member member=new Member();
	    member=memberUpdateService.SelectByUserName(username);
		Gson g=new Gson();
		String json = g.toJson(member);
		return json;
	}
	
	@RequestMapping(value="/UpdateByUserName",method=RequestMethod.GET)
	@ResponseBody
	public String UpdateByUserName(HttpServletRequest req){
		String username=req.getParameter("username");
		String password=req.getParameter("password");
	    Member member=new Member();
	    member.setUsername(username);
	    member.setPassword(password);
	    int result=memberUpdateService.UpdateByUserName(member);
		Gson g=new Gson();
		String json = g.toJson(result);
		return json;
	}
	
	
}
